package com.komodo.island.gdx.game.underwater;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.actors.Button;
import com.badlogic.gdx.scenes.scene2d.actors.Image;
import com.komodo.island.gdx.Art;
import com.komodo.island.gdx.Input;
import com.komodo.island.gdx.KomodoIsland;
import com.komodo.island.gdx.Persistence;
import com.komodo.island.gdx.dialog.Dialog;
import com.komodo.island.gdx.screen.GameScreen;
import com.komodo.island.gdx.screen.Screen;

public class UnderwaterStage extends Dialog {

	public Button shutter;
	public Image blitz;

	public UnderwaterStage(float width, float height, boolean stretch,
			Screen screen, Texture texture,KomodoIsland komodoIsland) {
		super(width, height, stretch, screen, texture,komodoIsland);
		// TODO Auto-generated constructor stub
	// TODO Auto-generated constructor stub
		this.ID = Input.DIALOG_UNDERWATER;

		// setBackground(0 , 0, 1440, 320);
	}

	@Override
	public void init() {
		shutter = new Button("shutter", new TextureRegion(texture, 128 * 2,
				320, 96, 96));
		blitz = new Image("blitz",
				new TextureRegion(texture, 1440, 0, 480, 320));

	}

	@Override
	public void addElements() {
//		addActor(shutter);
	}

	@Override
	public void setThePosition() {
		shutter.x = 480 - 96;
		shutter.y = 320 - 96;

		blitz.x = 0;
		blitz.y = 0;

	}

	@Override
	public void setTheListener() {
		shutter.clickListener = new Button.ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				if (Persistence.sound)
					((KomodoUnderwater) screen).click.play(1);
				
				if (!((KomodoUnderwater) screen).shutterEffect) {
					Art.drawString("CLICK", 0, 0);
//					System.out.println("SHUTTER");
					addActor(blitz);
					((KomodoUnderwater) screen).shutterEffect = true;
					((KomodoUnderwater) screen).shutterStart = System
							.currentTimeMillis();
					((KomodoUnderwater) screen).timer.setSecond(3);
					removeActor(shutter);
					((KomodoUnderwater) screen).cekTarget();
				}

			}
		};
	}

	@Override
	public boolean touchUp(int x, int y, int pointer, int button) {
		// TODO Auto-generated method stub
		if (Persistence.sound)
		if (((GameScreen) screen).gameState == GameScreen.GAME_RUNNING)
			if (((KomodoUnderwater) screen).swype.isPlaying()) {
				((KomodoUnderwater) screen).swype.stop();
			}
		if (((GameScreen) screen).gameState == GameScreen.GAME_RUNNING)
		return super.touchUp(x, y, pointer, button);
		else
			return false;

	}

	@Override
	public boolean touchDragged(int x, int y, int pointer) {
		// TODO Auto-generated method stub
		if (Persistence.sound)
			if (((GameScreen) screen).gameState == GameScreen.GAME_RUNNING)
				if (!((KomodoUnderwater) screen).swype.isPlaying()) {
					((KomodoUnderwater) screen).swype.play();
				}
		// else
		// ((KomodoUnderwater)screen).swype.play();
		if (((GameScreen) screen).gameState == GameScreen.GAME_RUNNING)
		return super.touchDragged(x, y, pointer);
		else
			return false;
	}

	@Override
	public boolean touchDown(int x, int y, int pointer, int newParam) {
		// TODO Auto-generated method stub
		if (Persistence.sound)
		if (((GameScreen) screen).gameState == GameScreen.GAME_RUNNING)
			if (!((KomodoUnderwater) screen).swype.isPlaying()) {
				((KomodoUnderwater) screen).swype.play();
			}
		
		if (((GameScreen) screen).gameState == GameScreen.GAME_RUNNING)
		return super.touchDown(x, y, pointer, newParam);
		else return false;
	}
	
	@Override
	public void addActor(Actor actor) {
		// TODO Auto-generated method stub
		super.addActor(actor);
//		System.out.println(actor);
	}

}
